function addUsercheckTel() {
    var tel = document.getElementById('tel').value;
    if (tel == "") {
        $("#validateTel").html("账号不能为空！");
        return;
    }
    if (!(/^1[3456789]\d{9}$/.test(tel))) {
        $("#validateTel").html("账号格式错误，请重新输入！");
        return;
    }
    $.ajax({
        url: "validatePhone?tel=" + tel,
        type: "post",
        success: function (data) {
            console.log(data.validateResult)
            if (data.validateResult == "账号正常！") {
                $("#validateTel").html("账号已存在，不能进行添加！");
            } else if (data.validateResult == "账号不存在！") {
                $("#validateTel").html("账号可用！");
            }
        },
        error: function (data) {
            alert("error");
        }
    })


}

function addUserchecknickname() {
    var nickname = document.getElementById("nickname").value;
    if (nickname == "") {
        $("#validatenickname").html("名称不能为空！");
        return;
    } else {
        $("#validatenickname").html("名称可用！");
    }
}

$(function () {
    var selectCompany = $("#selectCompany");//银行
    var selectOrg = $("#selectOrg");//机构
    var selectLeft = $("#leftID");
    $.ajax({
        url: "getAllCompany",
        type: "GET",
        dataType: "json",
        success: function (data) {
            if (data != null) {
                var org = data.allComName;//机构
                var company = data.allBankName;//银行
                var role = data.allRoleName;//角色
                selectCompany.html("");
                selectOrg.html("");
                selectLeft.html("");
                //向银行select传入数据
                var options = "<option value=\"0\">--请选择--</option>";
                for (var i = 0; i < company.length; i++) {
                    options += "<option value=\"" + company[i].id + "\">" + company[i].bankname + "</option>";
                }
                //向机构select传入数据
                var optionss = "<option value=\"0\">--请选择--</option>";
                for (var i = 0; i < org.length; i++) {
                    optionss += "<option value=\"" + org[i][0] + "\">" + org[i][1] + "</option>";
                }
                //向leftselect的中传入数据
                var optionsss = "";
                for (var i = 0; i < role.length; i++) {
                    optionsss += "<option value=\"" + role[i].id + "\">" + role[i].rooname + "</option>";
                }
                selectCompany.html(options);
                selectOrg.html(optionss);
                selectLeft.html(optionsss);
            }
        }
    })
})


//确认密码验证
function checkPassword() {
    var password1 = $("#password1").val();
    var password2 = $("#password2").val();
    console.log(password1 + password2);
    if (password1 == "") {
        $("#passwordmsg1").html("密码不能为空！");
        return;
    }
    if (password2 == "") {
        $("#passwordmsg").html("确认密码不能为空！");
        return;
    }
    if (password1 == password2) {
        $("#passwordmsg").html("两次密码相同");
        $("#passwordmsg").css("color", "green");
        $("#saveBtn1").removeAttr("disabled");
    } else {
        $("#passwordmsg").html("两次密码不相同");
        $("#passwordmsg").css("color", "red");
        $("#saveBtn1").attr("disabled", "disabled");
    }
}


function saveUserInfo() {
    var tel = $("#tel").val();
    if (tel == "") {
        alert("请输入使用者账号!")
        return;
    }
    var nickname = $("#nickname").val();
    if (nickname == "") {
        alert("请输入使用者名称！");
        return;
    }
    var password = $("#password1").val();
    if (password == "") {
        alert("请输入密码！");
        return;
    }
    var password1 = $("#password2").val();
    if (password == "") {
        alert("请输入确认密码！");
        return;
    }
    var company = $("#selectCompany option:selected").val();
    if (company == "") {
        alert("请选择所属银行！");
        return;
    }
    var org = $("#selectOrg option:selected").val();
    if (org == "") {
        alert("请输入所属机构！")
        return;
    }
    var entrytime = $("#entrytime").val();
    if (entrytime == "") {
        alert("请输入入职时间");
        return;
    }
    if (rooleid == "") {
        alert("请为该角色添加职责（角色）！");
        return;
    }
    var linkmanname = $("#linkmanname").val();
    var linkmantel = $("#linkmantel").val();
    var companytel = $("#companytel").val();
    var email = $("#email").val();
    var rooleid = "";

    $("#rightID option:selected").each(function () {
        rooleid += $(this).val() + ",";
    });
    /*alert(rooleid);
    return;*/
    console.log("tel:" + tel + "，nickname:" + nickname + "，password:" + password + "，company" + company
        + "，org:" + org + "，entrytime:" + entrytime + "，linkmanname:" + linkmanname + "，linkmantel:" + linkmantel
        + "，companytel:" + companytel + "，email:" + email + "，rooleid:" + rooleid);
    $.ajax({
        url: "getAddUserInfo",
        type: "post",
        data: {
            username: nickname,
            password: password,
            tel: tel,
            bankid: company,
            organization: org,
            rooleid: rooleid,
            entryTime: entrytime,
            email: email,
            linkmanname: linkmanname,
            linkmantel: linkmantel,
            companytel: companytel,
        },
        success: function (data) {
            if (data.addUserResult == "添加成功") {
                alert("信息添加成功！");
                loadPage("systemManager/systemMain.html");
            } else {
                alert("信息添加失败！");
            }
        },
        error: function (data) {
            alert("error");
        }
    })
}

